package com.jy.api.dao;


import com.jy.api.domain.DiscountPromotion;
import com.jy.api.domain.PromotionType;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface DiscountPromotionDao extends JpaRepository<DiscountPromotion, Integer>, JpaSpecificationExecutor<DiscountPromotion> {

    @Query(value = "SELECT COUNT(*)  , p.product_id FROM `discount_promotion` dp  LEFT JOIN `discount_promotion_product` p on dp.`id`= p.`promotion_id`  AND dp.`promotion_type` IN (0,1) AND p.product_id IN (?1) and dp.store_id=?2", nativeQuery = true)
    List<Object[]> countByPromotionTypeAndProducts(List<String> productIds, String storeId);


    @Query(value = "SELECT COUNT(*)  , p.product_id FROM `discount_promotion` dp  LEFT JOIN `discount_promotion_product` p on dp.`id`= p.`promotion_id`  AND dp.`promotion_type` =1 AND p.product_id =?1 and dp.store_id=?2", nativeQuery = true)
    List<Object[]> countByPromotionTypeAndProduct(String productId, String storeId);


    List<DiscountPromotion> findAllByStoreIdAndPromotionTypeIn(String storeId,List<PromotionType> types);




}
